home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / distutils / sysconfig.py < prev    next >
Text File  |  2009-11-02  |  23KB  |  616 lines

  1. """Provide access to Python's configuration information.  The specific
  2. configuration variables available depend heavily on the platform and
  3. configuration.  The values may be retrieved using
  4. get_config_var(name), and the list of variables is available via
  5. get_config_vars().keys().  Additional convenience functions are also
  6. available.
  7.  
  8. Written by:   Fred L. Drake, Jr.
  9. Email:        <fdrake@acm.org>
  10. """
  11.  
  12. __revision__ = "$Id: sysconfig.py 75023 2009-09-22 19:31:34Z ronald.oussoren $"
  13.  
  14. import os
  15. import re
  16. import string
  17. import sys
  18.  
  19. from distutils.errors import DistutilsPlatformError
  20.  
  21. # These are needed in a couple of spots, so just compute them once.
  22. PREFIX = os.path.normpath(sys.prefix)
  23. EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  24.  
  25. # Path to the base directory of the project. On Windows the binary may
  26. # live in project/PCBuild9.  If we're dealing with an x64 Windows build,
  27. # it'll live in project/PCbuild/amd64.
  28. project_base = os.path.dirname(os.path.abspath(sys.executable))
  29. if os.name == "nt" and "pcbuild" in project_base[-8:].lower():
  30.     project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
  31. # PC/VS7.1
  32. if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower():
  33.     project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
  34.                                                 os.path.pardir))
  35. # PC/AMD64
  36. if os.name == "nt" and "\\pcbuild\\amd64" in project_base[-14:].lower():
  37.     project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
  38.                                                 os.path.pardir))
  39.  
  40. # python_build: (Boolean) if true, we're either building Python or
  41. # building an extension with an un-installed Python, so we use
  42. # different (hard-wired) directories.
  43. # Setup.local is available for Makefile builds including VPATH builds,
  44. # Setup.dist is available on Windows
  45. def _python_build():
  46.     for fn in ("Setup.dist", "Setup.local"):
  47.         if os.path.isfile(os.path.join(project_base, "Modules", fn)):
  48.             return True
  49.     return False
  50. python_build = _python_build()
  51.  
  52.  
  53. def get_python_version():
  54.     """Return a string containing the major and minor Python version,
  55.     leaving off the patchlevel.  Sample return values could be '1.5'
  56.     or '2.2'.
  57.     """
  58.     return sys.version[:3]
  59.  
  60.  
  61. def get_python_inc(plat_specific=0, prefix=None):
  62.     """Return the directory containing installed Python header files.
  63.  
  64.     If 'plat_specific' is false (the default), this is the path to the
  65.     non-platform-specific header files, i.e. Python.h and so on;
  66.     otherwise, this is the path to platform-specific header files
  67.     (namely pyconfig.h).
  68.  
  69.     If 'prefix' is supplied, use it instead of sys.prefix or
  70.     sys.exec_prefix -- i.e., ignore 'plat_specific'.
  71.     """
  72.     if prefix is None:
  73.         prefix = plat_specific and EXEC_PREFIX or PREFIX
  74.     if os.name == "posix":
  75.         if python_build:
  76.             base = os.path.dirname(os.path.abspath(sys.executable))
  77.             if plat_specific:
  78.                 inc_dir = base
  79.             else:
  80.                 inc_dir = os.path.join(base, "Include")
  81.                 if not os.path.exists(inc_dir):
  82.                     inc_dir = os.path.join(os.path.dirname(base), "Include")
  83.             return inc_dir
  84.         return os.path.join(prefix, "include",
  85.                             "python" + get_python_version() + (sys.pydebug and '_d' or ''))
  86.     elif os.name == "nt":
  87.         return os.path.join(prefix, "include")
  88.     elif os.name == "mac":
  89.         if plat_specific:
  90.             return os.path.join(prefix, "Mac", "Include")
  91.         else:
  92.             return os.path.join(prefix, "Include")
  93.     elif os.name == "os2":
  94.         return os.path.join(prefix, "Include")
  95.     else:
  96.         raise DistutilsPlatformError(
  97.             "I don't know where Python installs its C header files "
  98.             "on platform '%s'" % os.name)
  99.  
  100.  
  101. def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
  102.     """Return the directory containing the Python library (standard or
  103.     site additions).
  104.  
  105.     If 'plat_specific' is true, return the directory containing
  106.     platform-specific modules, i.e. any module from a non-pure-Python
  107.     module distribution; otherwise, return the platform-shared library
  108.     directory.  If 'standard_lib' is true, return the directory
  109.     containing standard Python library modules; otherwise, return the
  110.     directory for site-specific modules.
  111.  
  112.     If 'prefix' is supplied, use it instead of sys.prefix or
  113.     sys.exec_prefix -- i.e., ignore 'plat_specific'.
  114.     """
  115.     is_default_prefix = not prefix or os.path.normpath(prefix) in ('/usr', '/usr/local')
  116.     if prefix is None:
  117.         prefix = plat_specific and EXEC_PREFIX or PREFIX
  118.  
  119.     if os.name == "posix":
  120.         libpython = os.path.join(prefix,
  121.                                  "lib", "python" + get_python_version())
  122.         if standard_lib:
  123.             return libpython
  124.         elif is_default_prefix and 'PYTHONUSERBASE' not in os.environ and 'real_prefix' not in sys.__dict__:
  125.             return os.path.join(libpython, "dist-packages")
  126.         else:
  127.             return os.path.join(libpython, "site-packages")
  128.  
  129.     elif os.name == "nt":
  130.         if standard_lib:
  131.             return os.path.join(prefix, "Lib")
  132.         else:
  133.             if get_python_version() < "2.2":
  134.                 return prefix
  135.             else:
  136.                 return os.path.join(prefix, "Lib", "site-packages")
  137.  
  138.     elif os.name == "mac":
  139.         if plat_specific:
  140.             if standard_lib:
  141.                 return os.path.join(prefix, "Lib", "lib-dynload")
  142.             else:
  143.                 return os.path.join(prefix, "Lib", "site-packages")
  144.         else:
  145.             if standard_lib:
  146.                 return os.path.join(prefix, "Lib")
  147.             else:
  148.                 return os.path.join(prefix, "Lib", "site-packages")
  149.  
  150.     elif os.name == "os2":
  151.         if standard_lib:
  152.             return os.path.join(prefix, "Lib")
  153.         else:
  154.             return os.path.join(prefix, "Lib", "site-packages")
  155.  
  156.     else:
  157.         raise DistutilsPlatformError(
  158.             "I don't know where Python installs its library "
  159.             "on platform '%s'" % os.name)
  160.  
  161.  
  162. def customize_compiler(compiler):
  163.     """Do any platform-specific customization of a CCompiler instance.
  164.  
  165.     Mainly needed on Unix, so we can plug in the information that
  166.     varies across Unices and is stored in Python's Makefile.
  167.     """
  168.     if compiler.compiler_type == "unix":
  169.         (cc, cxx, opt, cflags, opt, extra_cflags, basecflags, ccshared, ldshared, so_ext) = \
  170.             get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
  171.                             'OPT', 'EXTRA_CFLAGS', 'BASECFLAGS',
  172.                             'CCSHARED', 'LDSHARED', 'SO')
  173.  
  174.         if 'CC' in os.environ:
  175.             cc = os.environ['CC']
  176.         if 'CXX' in os.environ:
  177.             cxx = os.environ['CXX']
  178.         if 'LDSHARED' in os.environ:
  179.             ldshared = os.environ['LDSHARED']
  180.         if 'CPP' in os.environ:
  181.             cpp = os.environ['CPP']
  182.         else:
  183.             cpp = cc + " -E"           # not always
  184.         if 'LDFLAGS' in os.environ:
  185.             ldshared = ldshared + ' ' + os.environ['LDFLAGS']
  186.         if 'BASECFLAGS' in os.environ:
  187.             basecflags = os.environ['BASECFLAGS']
  188.         if 'OPT' in os.environ:
  189.             opt = os.environ['OPT']
  190.         cflags = ' '.join(str(x) for x in (basecflags, opt, extra_cflags) if x)
  191.         if 'CFLAGS' in os.environ:
  192.             cflags = ' '.join(str(x) for x in (basecflags, opt, os.environ['CFLAGS'], extra_cflags) if x)
  193.             ldshared = ldshared + ' ' + os.environ['CFLAGS']
  194.         if 'CPPFLAGS' in os.environ:
  195.             cpp = cpp + ' ' + os.environ['CPPFLAGS']
  196.             cflags = cflags + ' ' + os.environ['CPPFLAGS']
  197.             ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
  198.  
  199.         cc_cmd = cc + ' ' + cflags
  200.         compiler.set_executables(
  201.             preprocessor=cpp,
  202.             compiler=cc_cmd,
  203.             compiler_so=cc_cmd + ' ' + ccshared,
  204.             compiler_cxx=cxx,
  205.             linker_so=ldshared,
  206.             linker_exe=cc)
  207.  
  208.         compiler.shared_lib_extension = so_ext
  209.  
  210.  
  211. def get_config_h_filename():
  212.     """Return full pathname of installed pyconfig.h file."""
  213.     if python_build:
  214.         if os.name == "nt":
  215.             inc_dir = os.path.join(project_base, "PC")
  216.         else:
  217.             inc_dir = project_base
  218.     else:
  219.         inc_dir = get_python_inc(plat_specific=1)
  220.     if get_python_version() < '2.2':
  221.         config_h = 'config.h'
  222.     else:
  223.         # The name of the config.h file changed in 2.2
  224.         config_h = 'pyconfig.h'
  225.     return os.path.join(inc_dir, config_h)
  226.  
  227.  
  228. def get_makefile_filename():
  229.     """Return full pathname of installed Makefile from the Python build."""
  230.     if python_build:
  231.         return os.path.join(os.path.dirname(sys.executable), "Makefile")
  232.     lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
  233.     return os.path.join(lib_dir, "config" + (sys.pydebug and "_d" or ""), "Makefile")
  234.  
  235.  
  236. def parse_config_h(fp, g=None):
  237.     """Parse a config.h-style file.
  238.  
  239.     A dictionary containing name/value pairs is returned.  If an
  240.     optional dictionary is passed in as the second argument, it is
  241.     used instead of a new dictionary.
  242.     """
  243.     if g is None:
  244.         g = {}
  245.     define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
  246.     undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
  247.     #
  248.     while 1:
  249.         line = fp.readline()
  250.         if not line:
  251.             break
  252.         m = define_rx.match(line)
  253.         if m:
  254.             n, v = m.group(1, 2)
  255.             try: v = int(v)
  256.             except ValueError: pass
  257.             g[n] = v
  258.         else:
  259.             m = undef_rx.match(line)
  260.             if m:
  261.                 g[m.group(1)] = 0
  262.     return g
  263.  
  264.  
  265. # Regexes needed for parsing Makefile (and similar syntaxes,
  266. # like old-style Setup files).
  267. _variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
  268. _findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
  269. _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
  270.  
  271. def parse_makefile(fn, g=None):
  272.     """Parse a Makefile-style file.
  273.  
  274.     A dictionary containing name/value pairs is returned.  If an
  275.     optional dictionary is passed in as the second argument, it is
  276.     used instead of a new dictionary.
  277.     """
  278.     from distutils.text_file import TextFile
  279.     fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
  280.  
  281.     if g is None:
  282.         g = {}
  283.     done = {}
  284.     notdone = {}
  285.  
  286.     while 1:
  287.         line = fp.readline()
  288.         if line is None:  # eof
  289.             break
  290.         m = _variable_rx.match(line)
  291.         if m:
  292.             n, v = m.group(1, 2)
  293.             v = v.strip()
  294.             # `$$' is a literal `$' in make
  295.             tmpv = v.replace('$$', '')
  296.  
  297.             if "$" in tmpv:
  298.                 notdone[n] = v
  299.             else:
  300.                 try:
  301.                     v = int(v)
  302.                 except ValueError:
  303.                     # insert literal `$'
  304.                     done[n] = v.replace('$$', '$')
  305.                 else:
  306.                     done[n] = v
  307.  
  308.     # do variable interpolation here
  309.     while notdone:
  310.         for name in notdone.keys():
  311.             value = notdone[name]
  312.             m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
  313.             if m:
  314.                 n = m.group(1)
  315.                 found = True
  316.                 if n in done:
  317.                     item = str(done[n])
  318.                 elif n in notdone:
  319.                     # get it on a subsequent round
  320.                     found = False
  321.                 elif n in os.environ:
  322.                     # do it like make: fall back to environment
  323.                     item = os.environ[n]
  324.                 else:
  325.                     done[n] = item = ""
  326.                 if found:
  327.                     after = value[m.end():]
  328.                     value = value[:m.start()] + item + after
  329.                     if "$" in after:
  330.                         notdone[name] = value
  331.                     else:
  332.                         try: value = int(value)
  333.                         except ValueError:
  334.                             done[name] = value.strip()
  335.                         else:
  336.                             done[name] = value
  337.                         del notdone[name]
  338.             else:
  339.                 # bogus variable reference; just drop it since we can't deal
  340.                 del notdone[name]
  341.  
  342.     fp.close()
  343.  
  344.     # save the results in the global dictionary
  345.     g.update(done)
  346.     return g
  347.  
  348.  
  349. def expand_makefile_vars(s, vars):
  350.     """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
  351.     'string' according to 'vars' (a dictionary mapping variable names to
  352.     values).  Variables not present in 'vars' are silently expanded to the
  353.     empty string.  The variable values in 'vars' should not contain further
  354.     variable expansions; if 'vars' is the output of 'parse_makefile()',
  355.     you're fine.  Returns a variable-expanded version of 's'.
  356.     """
  357.  
  358.     # This algorithm does multiple expansion, so if vars['foo'] contains
  359.     # "${bar}", it will expand ${foo} to ${bar}, and then expand
  360.     # ${bar}... and so forth.  This is fine as long as 'vars' comes from
  361.     # 'parse_makefile()', which takes care of such expansions eagerly,
  362.     # according to make's variable expansion semantics.
  363.  
  364.     while 1:
  365.         m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
  366.         if m:
  367.             (beg, end) = m.span()
  368.             s = s[0:beg] + vars.get(m.group(1)) + s[end:]
  369.         else:
  370.             break
  371.     return s
  372.  
  373.  
  374. _config_vars = None
  375.  
  376. def _init_posix():
  377.     """Initialize the module as appropriate for POSIX systems."""
  378.     g = {}
  379.     # load the installed Makefile:
  380.     try:
  381.         filename = get_makefile_filename()
  382.         parse_makefile(filename, g)
  383.     except IOError, msg:
  384.         my_msg = "invalid Python installation: unable to open %s" % filename
  385.         if hasattr(msg, "strerror"):
  386.             my_msg = my_msg + " (%s)" % msg.strerror
  387.  
  388.         raise DistutilsPlatformError(my_msg)
  389.  
  390.     # load the installed pyconfig.h:
  391.     try:
  392.         filename = get_config_h_filename()
  393.         parse_config_h(file(filename), g)
  394.     except IOError, msg:
  395.         my_msg = "invalid Python installation: unable to open %s" % filename
  396.         if hasattr(msg, "strerror"):
  397.             my_msg = my_msg + " (%s)" % msg.strerror
  398.  
  399.         raise DistutilsPlatformError(my_msg)
  400.  
  401.     # On MacOSX we need to check the setting of the environment variable
  402.     # MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
  403.     # it needs to be compatible.
  404.     # If it isn't set we set it to the configure-time value
  405.     if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
  406.         cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
  407.         cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
  408.         if cur_target == '':
  409.             cur_target = cfg_target
  410.             os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
  411.         elif map(int, cfg_target.split('.')) > map(int, cur_target.split('.')):
  412.             my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure'
  413.                 % (cur_target, cfg_target))
  414.             raise DistutilsPlatformError(my_msg)
  415.  
  416.     # On AIX, there are wrong paths to the linker scripts in the Makefile
  417.     # -- these paths are relative to the Python source, but when installed
  418.     # the scripts are in another directory.
  419.     if python_build:
  420.         g['LDSHARED'] = g['BLDSHARED']
  421.  
  422.     elif get_python_version() < '2.1':
  423.         # The following two branches are for 1.5.2 compatibility.
  424.         if sys.platform == 'aix4':          # what about AIX 3.x ?
  425.             # Linker script is in the config directory, not in Modules as the
  426.             # Makefile says.
  427.             python_lib = get_python_lib(standard_lib=1)
  428.             ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
  429.             python_exp = os.path.join(python_lib, 'config', 'python.exp')
  430.  
  431.             g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
  432.  
  433.         elif sys.platform == 'beos':
  434.             # Linker script is in the config directory.  In the Makefile it is
  435.             # relative to the srcdir, which after installation no longer makes
  436.             # sense.
  437.             python_lib = get_python_lib(standard_lib=1)
  438.             linkerscript_path = string.split(g['LDSHARED'])[0]
  439.             linkerscript_name = os.path.basename(linkerscript_path)
  440.             linkerscript = os.path.join(python_lib, 'config',
  441.                                         linkerscript_name)
  442.  
  443.             # XXX this isn't the right place to do this: adding the Python
  444.             # library to the link, if needed, should be in the "build_ext"
  445.             # command.  (It's also needed for non-MS compilers on Windows, and
  446.             # it's taken care of for them by the 'build_ext.get_libraries()'
  447.             # method.)
  448.             g['LDSHARED'] = ("%s -L%s/lib -lpython%s" %
  449.                              (linkerscript, PREFIX, get_python_version()))
  450.  
  451.     global _config_vars
  452.     _config_vars = g
  453.  
  454.  
  455. def _init_nt():
  456.     """Initialize the module as appropriate for NT"""
  457.     g = {}
  458.     # set basic install directories
  459.     g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
  460.     g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
  461.  
  462.     # XXX hmmm.. a normal install puts include files here
  463.     g['INCLUDEPY'] = get_python_inc(plat_specific=0)
  464.  
  465.     g['SO'] = '.pyd'
  466.     g['EXE'] = ".exe"
  467.     g['VERSION'] = get_python_version().replace(".", "")
  468.     g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
  469.  
  470.     global _config_vars
  471.     _config_vars = g
  472.  
  473.  
  474. def _init_mac():
  475.     """Initialize the module as appropriate for Macintosh systems"""
  476.     g = {}
  477.     # set basic install directories
  478.     g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
  479.     g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
  480.  
  481.     # XXX hmmm.. a normal install puts include files here
  482.     g['INCLUDEPY'] = get_python_inc(plat_specific=0)
  483.  
  484.     import MacOS
  485.     if not hasattr(MacOS, 'runtimemodel'):
  486.         g['SO'] = '.ppc.slb'
  487.     else:
  488.         g['SO'] = '.%s.slb' % MacOS.runtimemodel
  489.  
  490.     # XXX are these used anywhere?
  491.     g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
  492.     g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
  493.  
  494.     # These are used by the extension module build
  495.     g['srcdir'] = ':'
  496.     global _config_vars
  497.     _config_vars = g
  498.  
  499.  
  500. def _init_os2():
  501.     """Initialize the module as appropriate for OS/2"""
  502.     g = {}
  503.     # set basic install directories
  504.     g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
  505.     g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
  506.  
  507.     # XXX hmmm.. a normal install puts include files here
  508.     g['INCLUDEPY'] = get_python_inc(plat_specific=0)
  509.  
  510.     g['SO'] = '.pyd'
  511.     g['EXE'] = ".exe"
  512.  
  513.     global _config_vars
  514.     _config_vars = g
  515.  
  516.  
  517. def get_config_vars(*args):
  518.     """With no arguments, return a dictionary of all configuration
  519.     variables relevant for the current platform.  Generally this includes
  520.     everything needed to build extensions and install both pure modules and
  521.     extensions.  On Unix, this means every variable defined in Python's
  522.     installed Makefile; on Windows and Mac OS it's a much smaller set.
  523.  
  524.     With arguments, return a list of values that result from looking up
  525.     each argument in the configuration variable dictionary.
  526.     """
  527.     global _config_vars
  528.     if _config_vars is None:
  529.         func = globals().get("_init_" + os.name)
  530.         if func:
  531.             func()
  532.         else:
  533.             _config_vars = {}
  534.  
  535.         # Normalized versions of prefix and exec_prefix are handy to have;
  536.         # in fact, these are the standard versions used most places in the
  537.         # Distutils.
  538.         _config_vars['prefix'] = PREFIX
  539.         _config_vars['exec_prefix'] = EXEC_PREFIX
  540.  
  541.         if sys.platform == 'darwin':
  542.             kernel_version = os.uname()[2] # Kernel version (8.4.3)
  543.             major_version = int(kernel_version.split('.')[0])
  544.  
  545.             if major_version < 8:
  546.                 # On Mac OS X before 10.4, check if -arch and -isysroot
  547.                 # are in CFLAGS or LDFLAGS and remove them if they are.
  548.                 # This is needed when building extensions on a 10.3 system
  549.                 # using a universal build of python.
  550.                 for key in ('LDFLAGS', 'BASECFLAGS',
  551.                         # a number of derived variables. These need to be
  552.                         # patched up as well.
  553.                         'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
  554.                     flags = _config_vars[key]
  555.                     flags = re.sub('-arch\s+\w+\s', ' ', flags)
  556.                     flags = re.sub('-isysroot [^ \t]*', ' ', flags)
  557.                     _config_vars[key] = flags
  558.  
  559.             else:
  560.  
  561.                 # Allow the user to override the architecture flags using
  562.                 # an environment variable.
  563.                 # NOTE: This name was introduced by Apple in OSX 10.5 and
  564.                 # is used by several scripting languages distributed with
  565.                 # that OS release.
  566.  
  567.                 if 'ARCHFLAGS' in os.environ:
  568.                     arch = os.environ['ARCHFLAGS']
  569.                     for key in ('LDFLAGS', 'BASECFLAGS',
  570.                         # a number of derived variables. These need to be
  571.                         # patched up as well.
  572.                         'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
  573.  
  574.                         flags = _config_vars[key]
  575.                         flags = re.sub('-arch\s+\w+\s', ' ', flags)
  576.                         flags = flags + ' ' + arch
  577.                         _config_vars[key] = flags
  578.  
  579.                 # If we're on OSX 10.5 or later and the user tries to
  580.                 # compiles an extension using an SDK that is not present
  581.                 # on the current machine it is better to not use an SDK
  582.                 # than to fail.
  583.                 #
  584.                 # The major usecase for this is users using a Python.org
  585.                 # binary installer  on OSX 10.6: that installer uses
  586.                 # the 10.4u SDK, but that SDK is not installed by default
  587.                 # when you install Xcode.
  588.                 #
  589.                 m = re.search('-isysroot\s+(\S+)', _config_vars['CFLAGS'])
  590.                 if m is not None:
  591.                     sdk = m.group(1)
  592.                     if not os.path.exists(sdk):
  593.                         for key in ('LDFLAGS', 'BASECFLAGS',
  594.                              # a number of derived variables. These need to be
  595.                              # patched up as well.
  596.                             'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
  597.  
  598.                             flags = _config_vars[key]
  599.                             flags = re.sub('-isysroot\s+\S+(\s|$)', ' ', flags)
  600.                             _config_vars[key] = flags
  601.  
  602.     if args:
  603.         vals = []
  604.         for name in args:
  605.             vals.append(_config_vars.get(name))
  606.         return vals
  607.     else:
  608.         return _config_vars
  609.  
  610. def get_config_var(name):
  611.     """Return the value of a single variable using the dictionary
  612.     returned by 'get_config_vars()'.  Equivalent to
  613.     get_config_vars().get(name)
  614.     """
  615.     return get_config_vars().get(name)
  616.